<template>
  <div>
    <button @click="toLogin">登录</button>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from "vue-router";
import { useUserStore } from "@/store/userStore";

const userStore = useUserStore();

const router = useRouter();

const toLogin = () => {
  const loginData = {
    username: "admin",
    password: "123456",
  };

  userStore
    .login(loginData)
    .then(() => {
      router.push({ path: "/index" });
    })
    .catch(() => {
      console.log("登录失败");
    });
};
</script>
